package com.hxkcloud.patient.fragments;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hyphenate.easeui.EaseConstant;
import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;
import com.hxkcloud.patient.activitys.ChatFragmentActivity;
import com.hxkcloud.patient.activitys.MessageMainActivity;
import com.hxkcloud.patient.activitys.MonitorChart1Activity;
import com.hxkcloud.patient.activitys.PatientBetterPlanActivity;
import com.hxkcloud.patient.activitys.PatientInfoActivity;
import com.hxkcloud.patient.activitys.SearchUserManagerActivity;
import com.hxkcloud.patient.adapter.FilterListAdapter;
import com.hxkcloud.patient.beans.DepartmentBean;
import com.hxkcloud.patient.beans.DiseaseBean;
import com.hxkcloud.patient.beans.FilterBean;
import com.hxkcloud.patient.beans.FilterItem;
import com.hxkcloud.patient.beans.FilterListBean;
import com.hxkcloud.patient.beans.FilterPatientBean;
import com.hxkcloud.patient.beans.HospitalStatusBean;
import com.hxkcloud.patient.beans.UserManagerBean;
import com.hxkcloud.patient.beans.UserManagerInfo;
import com.hxkcloud.patient.beans.resultbeans.ObjectResultBean;
import com.hxkcloud.patient.dborm.DepartmentDao;
import com.hxkcloud.patient.popup.DatePopWindow;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.patient.utils.ImageUtil;
import com.hxkcloud.patient.views.pulltorefreshlayout.PullToRefreshLayout;
import com.hxkcloud.patient.views.pulltorefreshlayout.PullableRecyclerView;
import com.hxkcloud.patient.adapter.UserManagerAdapter;

import android.support.v7.widget.LinearLayoutManager;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户管理
 */
public class UserManagerFragment extends BaseFragment implements View.OnClickListener, PullToRefreshLayout.OnRefreshListener, UserManagerAdapter.ResultSelectedListener {

    private View view;

    private LinearLayout ll_title;
    private ImageView iv_search;
    private TextView tv_title;
    private ImageView iv_message;
    private ImageView iv_msgpoint;

    private TextView tv_count;//患者总数

    private LinearLayout ll_empty;
    private LinearLayout ll_info;

    private LinearLayout ivgLayout;//导航布局

    private LinearLayout display1Layout;
    private LinearLayout display2Layout;
    private LinearLayout display3Layout;
    private LinearLayout display4Layout;
    private TextView display1TV;
    private TextView display2TV;
    private TextView display3TV;
    private TextView display4TV;
    private ImageView display1IV;
    private ImageView display2IV;
    private ImageView display3IV;
    private ImageView display4IV;
    private View middleView1;
    private View middleView2;
    private View middleView3;

    private PopupWindow allPopup;//选择全部
    private ListView allListView;
    private FilterListAdapter allAdapter;

    private View allWholeView;

    private DatePopWindow datePopup;


    private PullToRefreshLayout refreshLayout;
    private PullableRecyclerView recycleView;

    private List<UserManagerBean> userManagerInfoList;
    private UserManagerAdapter adapter;

    private String inHospital = "";//状态
    private String disease = "";//病种
    private String date = "";//时间   格式：时间戳
    private String dateKind = "";//时间类型
    private String keyword = "";//关键字

    private int pageIndex = 1;
    private int pageSize = 15;

    private boolean isLoadMore = false;// 是否加载更多

    private ObjectResultBean<UserManagerInfo> resultBean;

    private int totalCount = 0;

    private boolean isAllClick = false;

    private String statusName = "";

    private List<HospitalStatusBean> statusBeans;
    private List<DiseaseBean> diseaseBeans;
    private String statusDefault = "在院";


    private List<FilterItem> filterItems;

    private ObjectResultBean<FilterListBean> filterBean;

    private List<FilterBean> listBeans;

    private boolean isDisplay1 = false;
    private boolean isDisplay2 = false;
    private boolean isDisplay3 = false;
    private boolean isDisplay4 = false;

    private int clickNum = 1;//1 2 3

    private String display1Default = "";
    private String display2Default = "";
    private String display3Default = "";
    private String display4Default = "";
    private String display1Id = "";
    private String display2Id = "";
    private String display3Id = "";
    private String display4Id = "";
    private String display1Type = "";
    private String display2Type = "";
    private String display3Type = "";
    private String display4Type = "";

    private List<FilterPatientBean> filterList;//筛选条件集合

    private boolean isChanke = false;

    private boolean isDisplay1Click = true;
    private boolean isDisplay2Click = true;
    private boolean isDisplay3Click = true;
    private boolean isDisplay4Click = true;


    public void showPoint(boolean show, String jpushType) {
        if (iv_msgpoint != null) {
            if (show) {
                iv_msgpoint.setVisibility(View.VISIBLE);
            } else {
                iv_msgpoint.setVisibility(View.INVISIBLE);
            }
        }
        if ((!TextUtils.isEmpty(jpushType)) && (jpushType.equals("3"))) {
            if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                initData();
                ll_empty.setVisibility(View.GONE);
                ll_info.setVisibility(View.VISIBLE);
            }
        }
    }

    public void jpushRefreshPatients() {
        if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            initData();
            ll_empty.setVisibility(View.GONE);
            ll_info.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERNEWLIST_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    resultBean = (ObjectResultBean<UserManagerInfo>) msg.obj;
                    totalCount = Integer.parseInt(resultBean.getData().getTotalCount());
                    if (resultBean.getData().getList().size() == 0) {
                        if (isLoadMore) {
                            refreshLayout
                                    .loadmoreFinish(PullToRefreshLayout.SUCCEED);
                        } else {
                            userManagerInfoList.clear();
                            adapter.setData(userManagerInfoList);
                            refreshLayout
                                    .refreshFinish(PullToRefreshLayout.SUCCEED);
                        }
                    } else {
                        if (isLoadMore) {

                        } else {
                            userManagerInfoList.clear();
                        }
                        userManagerInfoList.addAll(resultBean.getData().getList());
                        adapter.setData(userManagerInfoList);
                        if (isLoadMore) {
                            refreshLayout
                                    .loadmoreFinish(PullToRefreshLayout.SUCCEED);
                        } else {
                            refreshLayout
                                    .refreshFinish(PullToRefreshLayout.SUCCEED);
                        }

                    }

                    if (totalCount > 0) {
                        tv_count.setText(totalCount + "人");
                        tv_count.setVisibility(View.VISIBLE);
                    } else {
                        tv_count.setVisibility(View.GONE);
                    }
                }

                break;
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERNEWLIST_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }
                break;

            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERLIST_SUCCESS:
                dismisssLoading();
                if (msg.obj != null) {
                    filterBean = (ObjectResultBean<FilterListBean>) msg.obj;
                    listBeans = filterBean.getData().getList();
                    if (listBeans != null && listBeans.size() > 0) {
                        if (listBeans.size() == 1) {
                            display1Layout.setVisibility(View.VISIBLE);
                            display2Layout.setVisibility(View.GONE);
                            display3Layout.setVisibility(View.GONE);
                            display4Layout.setVisibility(View.GONE);
                            middleView1.setVisibility(View.GONE);
                            middleView2.setVisibility(View.GONE);
                            middleView3.setVisibility(View.GONE);
                        } else if (listBeans.size() == 2) {
                            display1Layout.setVisibility(View.VISIBLE);
                            display2Layout.setVisibility(View.VISIBLE);
                            display3Layout.setVisibility(View.GONE);
                            display4Layout.setVisibility(View.GONE);
                            middleView2.setVisibility(View.GONE);
                            middleView3.setVisibility(View.GONE);
                        } else if (listBeans.size() == 3) {
                            display1Layout.setVisibility(View.VISIBLE);
                            display2Layout.setVisibility(View.VISIBLE);
                            display3Layout.setVisibility(View.VISIBLE);
                            display4Layout.setVisibility(View.GONE);
                            middleView3.setVisibility(View.GONE);
                        } else if (listBeans.size() == 4) {
                            display1Layout.setVisibility(View.VISIBLE);
                            display2Layout.setVisibility(View.VISIBLE);
                            display3Layout.setVisibility(View.VISIBLE);
                            display4Layout.setVisibility(View.VISIBLE);
                        }
                        for (int i = 0; i < listBeans.size(); i++) {
                            if (i == 0) {
                                display1Default = listBeans.get(i).getFilterName();
                                display1Id = listBeans.get(i).getFilterId();
                                display1Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display1TV.setText(display1Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display1TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                display1TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display1Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display1Id);
                                                bean.setFilterName(display1Default);
                                                bean.setFilterType(display1Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display1TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display1TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            } else if (i == 1) {
                                display2Default = listBeans.get(i).getFilterName();
                                display2Id = listBeans.get(i).getFilterId();
                                display2Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display2TV.setText(display2Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display2TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                display2TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display2Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display2Id);
                                                bean.setFilterName(display2Default);
                                                bean.setFilterType(display2Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display2TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display2TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            } else if (i == 2) {
                                display3Default = listBeans.get(i).getFilterName();
                                display3Id = listBeans.get(i).getFilterId();
                                display3Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display3TV.setText(display3Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display3TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                display3TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display3Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display3Id);
                                                bean.setFilterName(display3Default);
                                                bean.setFilterType(display3Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display3TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display3TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            } else if (i == 3) {
                                display4Default = listBeans.get(i).getFilterName();
                                display4Id = listBeans.get(i).getFilterId();
                                display4Type = listBeans.get(i).getFilterType();
                                if ("1".equals(listBeans.get(i).getFilterType())) {//时间
                                    display4TV.setText(display4Default);
                                } else if ("2".equals(listBeans.get(i).getFilterType())) {
                                    display4TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                    if (isChanke) {

                                    } else {
                                        for (int j = 0; j < listBeans.get(i).getFilterList().size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(listBeans.get(i).getFilterList().get(j).getItemName())) {
                                                display4TV.setText(listBeans.get(i).getFilterList().get(j).getItemName());
                                                removeFilterListItem(display4Id);
                                                FilterPatientBean bean = new FilterPatientBean();
                                                bean.setDate("");
                                                bean.setDateKind("");
                                                bean.setFilterId(display4Id);
                                                bean.setFilterName(display4Default);
                                                bean.setFilterType(display4Type);
                                                bean.setItemId(listBeans.get(i).getFilterList().get(j).getItemId());
                                                filterList.add(bean);
                                                break;
                                            }
                                        }
                                    }
                                } else if ("5".equals(listBeans.get(i).getFilterType())) {//自理能力
                                    display4TV.setText(mContext.getResources().getString(R.string.disability_level));
                                } else {
                                    display4TV.setText(listBeans.get(i).getFilterList().get(0).getItemName());
                                }
                            }
                        }
                        loading();
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                    } else {
                        ivgLayout.setVisibility(View.GONE);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                    }

                }
                break;
            case MessageCode.PREGNANTBMIADD_GETPATIENTFILTERLIST_FAILURE:
                dismisssLoading();
                if (msg.obj != null) {
                    toastMsg((String) msg.obj);
                }
                break;

        }

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        super.onCreateView(inflater, container, savedInstanceState);
        view = inflater.inflate(R.layout.fragment_layout_usermanager, container, false);
        userManagerInfoList = new ArrayList<>();
        listBeans = new ArrayList<>();
        filterItems = new ArrayList<>();
        filterList = new ArrayList<>();
        initView();
        initListener();
//        initData();

        return view;

    }

    @Override
    public void onResume() {
        super.onResume();
        if (TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            ll_empty.setVisibility(View.VISIBLE);
            ll_info.setVisibility(View.GONE);
        } else {
            isDisplay1 = false;
            isDisplay2 = false;
            isDisplay3 = false;
            isDisplay4 = false;
            initData();
            ll_empty.setVisibility(View.GONE);
            ll_info.setVisibility(View.VISIBLE);
        }

        if (YjhApplication.msg_new) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void initView() {

        ll_title = (LinearLayout) view.findViewById(R.id.ll_title);
        iv_search = (ImageView) view.findViewById(R.id.iv_title_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title_title);
        iv_message = (ImageView) view.findViewById(R.id.iv_title_func);
        iv_msgpoint = (ImageView) view.findViewById(R.id.iv_title_point);

        setTitlePadding(ll_title);
        iv_search.setVisibility(View.VISIBLE);
        iv_search.setImageResource(R.mipmap.nav_search);
        tv_title.setText(getResources().getText(R.string.usermanger_text));
        iv_message.setVisibility(View.VISIBLE);
        iv_message.setImageResource(R.mipmap.nav_message);
        iv_search.setOnClickListener(this);
        iv_message.setOnClickListener(this);

        tv_count = (TextView) view.findViewById(R.id.usermanager_count);
        ll_empty = (LinearLayout) view.findViewById(R.id.ll_department_empty);
        ll_info = (LinearLayout) view.findViewById(R.id.ll_usermanager_info);

        ivgLayout = (LinearLayout) view.findViewById(R.id.usermanager_layout_ivg);

        display1Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display1);
        display2Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display2);
        display3Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display3);
        display4Layout = (LinearLayout) view.findViewById(R.id.usermanager_layout_display4);

        display1TV = (TextView) view.findViewById(R.id.usermanager_tv_display1);
        display2TV = (TextView) view.findViewById(R.id.usermanager_tv_display2);
        display3TV = (TextView) view.findViewById(R.id.usermanager_tv_display3);
        display4TV = (TextView) view.findViewById(R.id.usermanager_tv_display4);

        display1IV = (ImageView) view.findViewById(R.id.usermanager_iv_display1);
        display2IV = (ImageView) view.findViewById(R.id.usermanager_iv_display2);
        display3IV = (ImageView) view.findViewById(R.id.usermanager_iv_display3);
        display4IV = (ImageView) view.findViewById(R.id.usermanager_iv_display4);

        middleView1 = (View) view.findViewById(R.id.usermanager_view_view1);
        middleView2 = (View) view.findViewById(R.id.usermanager_view_view2);
        middleView3 = (View) view.findViewById(R.id.usermanager_view_view3);


        refreshLayout = (PullToRefreshLayout) view.findViewById(R.id.usermanager_refreshlayout);
        recycleView = (PullableRecyclerView) view.findViewById(R.id.usermanager_recyclerview);

        RelativeLayout.LayoutParams lp_count = new RelativeLayout.LayoutParams(screenWidth / 10, screenWidth / 10);
        lp_count.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        lp_count.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        lp_count.bottomMargin = ImageUtil.dip2px(15, mContext);
        lp_count.rightMargin = ImageUtil.dip2px(10, mContext);
        tv_count.setLayoutParams(lp_count);

        LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(mLayoutManager);
//        ListDividerItemDecoration itemDecoration = new ListDividerItemDecoration(
//                getActivity(), ListDividerItemDecoration.VERTICAL_LIST);
//        recycleView.addItemDecoration(itemDecoration);

        adapter = new UserManagerAdapter(getActivity(), userManagerInfoList, recycleView, this, screenWidth, loginInfo.getDepartmentId());
        recycleView.setAdapter(adapter);

        initAllPopup();

    }

    @Override
    protected void initListener() {

        iv_search.setOnClickListener(this);

        display1Layout.setOnClickListener(this);
        display2Layout.setOnClickListener(this);
        display3Layout.setOnClickListener(this);
        display4Layout.setOnClickListener(this);

        iv_message.setOnClickListener(this);

        refreshLayout.setOnRefreshListener(this);
    }

    @Override
    protected void initData() {

        DepartmentDao dao = new DepartmentDao(mContext);
        List<DepartmentBean> beans = dao.getDepartment();
        if (beans != null) {
            for (int i = 0; i < beans.size(); i++) {
                if ((beans.get(i).getDepartmentId() + "").equals(loginInfo.getDepartmentId())) {
                    if ("0".equals(beans.get(i).getType())) {
                        isChanke = true;
                    }
                    break;
                }
            }
        }


        adapter = new UserManagerAdapter(getActivity(), userManagerInfoList, recycleView, this, screenWidth, loginInfo.getDepartmentId());
        recycleView.setAdapter(adapter);

        loading();
        YiJiaHuNetWorkUtils.getPatientFilterList(loginInfo.getDepartmentId(), handler);
        pageIndex = 1;

    }

    private void setInitPopup() {

        display1TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display1IV.setImageResource(R.mipmap.tab_arrow);


        display2TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display2IV.setImageResource(R.mipmap.tab_arrow);

        display3TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display3IV.setImageResource(R.mipmap.tab_arrow);

        display4TV.setTextColor(mContext.getResources().getColor(R.color.black_text));
        display4IV.setImageResource(R.mipmap.tab_arrow);
    }

    private void initAllPopup() {
        allPopup = new PopupWindow(getActivity());
        View allView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_layout_kind, null);
        allPopup.setContentView(allView);

        allPopup.setWidth(screenWidth);
        allPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        allPopup.setFocusable(true);
        allPopup.setTouchable(true);
        allPopup.setOutsideTouchable(true);
        allPopup.setBackgroundDrawable(new ColorDrawable(0x00000000));


        allListView = (ListView) allView.findViewById(R.id.kind_listview);
        allAdapter = new FilterListAdapter(getActivity(), filterItems);
        allListView.setAdapter(allAdapter);
        allListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                for (int i = 0; i < filterItems.size(); i++) {
                    if (i == position) {
                        filterItems.get(i).setIsSelect(true);
                        statusName = filterItems.get(i).getItemName();
                    } else {
                        filterItems.get(i).setIsSelect(false);
                    }
                }
                FilterPatientBean bean = new FilterPatientBean();
                bean.setDate("");
                bean.setDateKind("");
                if (clickNum == 1) {
                    isDisplay1 = true;
//                    display1TV.setText(filterItems.get(position).getItemName());
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display1Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display1TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display1TV.setText(displayName + "...");
                        } else {
                            display1TV.setText(name);
                        }
                    }
                    if ("2".equals(display1Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay2Click = true;
                        isDisplay3Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display2Layout.setEnabled(true);
                        display3Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                            display2TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                            display3TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    display1IV.setImageResource(R.mipmap.tab_arrow);
                    removeFilterListItem(display1Id);
                    bean.setFilterId(display1Id);
                    bean.setFilterName(display1Default);
                    bean.setFilterType(display1Type);
                    bean.setItemId(filterItems.get(position).getItemId());

                } else if (clickNum == 2) {
                    isDisplay2 = true;
//                    display2TV.setText(filterItems.get(position).getItemName());
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display2Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display2TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display2TV.setText(displayName + "...");
                        } else {
                            display2TV.setText(name);
                        }
                    }
                    if ("2".equals(display2Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay2Click = true;
                        isDisplay3Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display2Layout.setEnabled(true);
                        display3Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                            display2TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                            display3TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }

                    display2IV.setImageResource(R.mipmap.tab_arrow);
                    removeFilterListItem(display2Id);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                } else if (clickNum == 3) {
                    isDisplay3 = true;
//                    display3TV.setText(filterItems.get(position).getItemName());
                    String name = filterItems.get(position).getItemName();

                    if ("5".equals(display3Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display3TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display3TV.setText(displayName + "...");
                        } else {
                            display3TV.setText(name);
                        }
                    }
                    if ("2".equals(display3Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay2Click = true;
                        isDisplay3Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display2Layout.setEnabled(true);
                        display3Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                            display2TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                            display3TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    display3IV.setImageResource(R.mipmap.tab_arrow);
                    removeFilterListItem(display3Id);
                    bean.setFilterId(display3Id);
                    bean.setFilterName(display3Default);
                    bean.setFilterType(display3Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                } else if (clickNum == 4) {
                    isDisplay4 = true;
//                    display4TV.setText(filterItems.get(position).getItemName());
                    String name = filterItems.get(position).getItemName();
                    if ("5".equals(display4Type) && "-1".equals(filterItems.get(position).getItemId())) {
                        display4TV.setText(mContext.getResources().getString(R.string.disability_level));
                    } else {
                        if (name.length() > 4) {
                            String displayName = name.substring(0, 3);
                            display4TV.setText(displayName + "...");
                        } else {
                            display4TV.setText(name);
                        }
                    }
                    if ("2".equals(display4Type) && !"in".equals(filterItems.get(position).getItemId())) {
                        isDisplay1Click = true;
                        isDisplay2Click = true;
                        isDisplay3Click = true;
                        isDisplay4Click = true;
                        display1Layout.setEnabled(true);
                        display2Layout.setEnabled(true);
                        display3Layout.setEnabled(true);
                        display4Layout.setEnabled(true);
                    }
                    if ("2".equals(display1Type) && "in".equals(filterItems.get(position).getItemId())) {
                        if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                            display1TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                            display2TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                            display3TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        } else if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                            display4TV.setText(mContext.getResources().getString(R.string.usermanger_text_time));
                        }
                        removeFilterTimeItem();
                    }
                    display4IV.setImageResource(R.mipmap.tab_arrow);
                    removeFilterListItem(display4Id);
                    bean.setFilterId(display4Id);
                    bean.setFilterName(display4Default);
                    bean.setFilterType(display4Type);
                    bean.setItemId(filterItems.get(position).getItemId());
                }
                filterList.add(bean);

                allAdapter.notifyDataSetChanged();
                allPopup.dismiss();
                loading();
                YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

            }
        });
        allAdapter.setDisplayListener(new FilterListAdapter.DisplayListener() {
            @Override
            public void onDisplay(int position) {

            }
        });

        allWholeView = (View) allView.findViewById(R.id.kind_view_whole);
        allWholeView.setOnClickListener(this);

        allPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                display1IV.setImageResource(R.mipmap.tab_arrow);
                display2IV.setImageResource(R.mipmap.tab_arrow);
                display3IV.setImageResource(R.mipmap.tab_arrow);
                display4IV.setImageResource(R.mipmap.tab_arrow);
            }
        });
    }

    private void removeFilterTimeItem() {
        if (filterList != null && filterList.size() > 0) {
            for (int i = 0; i < filterList.size(); i++) {
                if (filterList.get(i).getFilterName().equals(mContext.getResources().getString(R.string.usermanger_text_time))) {
                    filterList.remove(i);
                }
            }
        }
    }

    private void removeFilterListItem(String kindId) {
        if (filterList != null && filterList.size() > 0) {
            for (int i = 0; i < filterList.size(); i++) {
                if (kindId.equals(filterList.get(i).getFilterId())) {
                    filterList.remove(i);
                }
            }
        }
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.usermanager_layout_display1:
                setInitPopup();
                clickNum = 1;
                display1IV.setImageResource(R.mipmap.tab_arrow_up);
                if (listBeans != null && listBeans.size() > 0) {
                    for (int i = 0; i < listBeans.size(); i++) {
                        if (i == 0) {
                            filterItems = listBeans.get(i).getFilterList();
                            if (filterItems.size() > 0) {
                                if (isDisplay1) {

                                } else {
                                    if (isChanke) {
                                        filterItems.get(0).setIsSelect(true);
                                    } else {
                                        for (int j = 0; j < filterItems.size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(filterItems.get(j).getItemName())) {
                                                filterItems.get(0).setIsSelect(false);
                                                filterItems.get(j).setIsSelect(true);
                                                break;
                                            } else {
                                                filterItems.get(0).setIsSelect(true);
                                            }
                                        }
                                    }

                                }
                            }
                            break;
                        }
                    }
                }
                if (filterItems != null && filterItems.size() > 0) {
                    allAdapter.setData(filterItems);
                    allPopup.showAsDropDown(ivgLayout);
                } else {
                    if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display1Default)) {
                        for (int i = 0; i < filterList.size(); i++) {
                            if (("2".equals(filterList.get(i).getFilterType()) && "in".equals(filterList.get(i).getItemId()))) {//
                                display1Layout.setEnabled(false);
                                display1IV.setImageResource(R.mipmap.tab_arrow);
                                isDisplay1Click = false;
                                break;
                            }
                        }

                        if (!isDisplay1Click) {
                            return;
                        } else {
                            showPopDate1();
                        }
                    } else {
                        showPopDate1();
                    }
                }

                break;
            case R.id.usermanager_layout_display2:

                setInitPopup();
                clickNum = 2;
                display2IV.setImageResource(R.mipmap.tab_arrow_up);
                if (listBeans != null && listBeans.size() > 0) {
                    for (int i = 0; i < listBeans.size(); i++) {
                        if (i == 1) {
                            filterItems = listBeans.get(i).getFilterList();
                            if (filterItems.size() > 0) {
                                if (isDisplay2) {

                                } else {
                                    if (isChanke) {
                                        filterItems.get(0).setIsSelect(true);
                                    } else {
                                        for (int j = 0; j < filterItems.size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(filterItems.get(j).getItemName())) {
                                                filterItems.get(0).setIsSelect(false);
                                                filterItems.get(j).setIsSelect(true);
                                                break;
                                            } else {
                                                filterItems.get(0).setIsSelect(true);
                                            }
                                        }
                                    }
                                }

                            }
                            break;
                        }
                    }
                }
                if (filterItems != null && filterItems.size() > 0) {
                    allAdapter.setData(filterItems);
                    allPopup.showAsDropDown(ivgLayout);
                } else {
                    if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display2Default)) {
                        for (int i = 0; i < filterList.size(); i++) {
                            if (("2".equals(filterList.get(i).getFilterType()) && "in".equals(filterList.get(i).getItemId()))) {//
                                display2IV.setImageResource(R.mipmap.tab_arrow);
                                display2Layout.setEnabled(false);
                                isDisplay2Click = false;
                                break;
                            }
                        }
                        if (!isDisplay2Click) {
                            return;
                        } else {
                            showPopDate2();
                        }
                    } else {
                        showPopDate2();
                    }
                }

                break;
            case R.id.usermanager_layout_display3:

                setInitPopup();
                clickNum = 3;
                display3IV.setImageResource(R.mipmap.tab_arrow_up);
                if (listBeans != null && listBeans.size() > 0) {
                    for (int i = 0; i < listBeans.size(); i++) {
                        if (i == 2) {
                            filterItems = listBeans.get(i).getFilterList();
                            if (filterItems.size() > 0) {
                                if (isDisplay3) {

                                } else {
                                    if (isChanke) {
                                        filterItems.get(0).setIsSelect(true);
                                    } else {
                                        for (int j = 0; j < filterItems.size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(filterItems.get(j).getItemName())) {
                                                filterItems.get(0).setIsSelect(false);
                                                filterItems.get(j).setIsSelect(true);
                                                break;
                                            } else {
                                                filterItems.get(0).setIsSelect(true);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                if (filterItems != null && filterItems.size() > 0) {
                    allAdapter.setData(filterItems);
                    allPopup.showAsDropDown(ivgLayout);
                } else {
                    if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display3Default)) {
                        for (int i = 0; i < filterList.size(); i++) {
                            if (("2".equals(filterList.get(i).getFilterType()) && "in".equals(filterList.get(i).getItemId()))) {//
                                display3IV.setImageResource(R.mipmap.tab_arrow);
                                display3Layout.setEnabled(false);
                                isDisplay3Click = false;
                                break;
                            }
                        }
                        if (!isDisplay3Click) {
                            return;
                        } else {
                            showPopDate3();
                        }

                    } else {
                        showPopDate3();
                    }
                }
                break;


            case R.id.usermanager_layout_display4:

                setInitPopup();
                clickNum = 4;
                display4IV.setImageResource(R.mipmap.tab_arrow_up);
                if (listBeans != null && listBeans.size() > 0) {
                    for (int i = 0; i < listBeans.size(); i++) {
                        if (i == 3) {
                            filterItems = listBeans.get(i).getFilterList();
                            if (filterItems.size() > 0) {
                                if (isDisplay4) {

                                } else {
                                    if (isChanke) {
                                        filterItems.get(0).setIsSelect(true);
                                    } else {
                                        for (int j = 0; j < filterItems.size(); j++) {
                                            if (mContext.getResources().getString(R.string.inhospital).equals(filterItems.get(j).getItemName())) {
                                                filterItems.get(0).setIsSelect(false);
                                                filterItems.get(j).setIsSelect(true);
                                                break;
                                            } else {
                                                filterItems.get(0).setIsSelect(true);
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                if (filterItems != null && filterItems.size() > 0) {
                    allAdapter.setData(filterItems);
                    allPopup.showAsDropDown(ivgLayout);
                } else {
                    if (mContext.getResources().getString(R.string.usermanger_text_time).equals(display4Default)) {
                        for (int i = 0; i < filterList.size(); i++) {
                            if (("2".equals(filterList.get(i).getFilterType()) && "in".equals(filterList.get(i).getItemId()))) {//
                                display4IV.setImageResource(R.mipmap.tab_arrow);
                                display4Layout.setEnabled(false);
                                isDisplay4Click = false;
                                break;
                            }
                        }
                        if (!isDisplay4Click) {
                            return;
                        } else {
                            showPopDate4();
                        }

                    } else {
                        showPopDate4();
                    }

                }
                break;


            case R.id.kind_view_whole:
                display1IV.setImageResource(R.mipmap.tab_arrow);
                display2IV.setImageResource(R.mipmap.tab_arrow);
                display3IV.setImageResource(R.mipmap.tab_arrow);
                allPopup.dismiss();

                break;
            case R.id.iv_title_back:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent intent = new Intent(getActivity(), SearchUserManagerActivity.class);
                    startActivity(intent);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
            case R.id.iv_title_func:
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent iM = new Intent(mContext, MessageMainActivity.class);
                    startActivity(iM);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
        }

    }


    private void showPopDate4() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                            display4TV.setText(display4Default);
                        }
                        date = "";
                        dateKind = "";
                        removeFilterListItem(display4Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display4Id);
                        bean.setFilterName(display4Default);
                        bean.setFilterType(display4Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    loading();
                    removeFilterListItem(display4Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display4Id);
                    bean.setFilterName(display4Default);
                    bean.setFilterType(display4Type);
                    bean.setItemId("");

                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display4TV.setText(displayDate);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display4TV.setText(displayTime);
                        display4IV.setImageResource(R.mipmap.tab_arrow);
                    }
                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate3() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                            display3TV.setText(display3Default);
                        }
                        date = "";
                        dateKind = "";
                        removeFilterListItem(display3Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display3Id);
                        bean.setFilterName(display3Default);
                        bean.setFilterType(display3Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        display3IV.setImageResource(R.mipmap.tab_arrow);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    loading();
                    removeFilterListItem(display3Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display3Id);
                    bean.setFilterName(display3Default);
                    bean.setFilterType(display3Type);
                    bean.setItemId("");

                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display3TV.setText(displayDate);
                        display3IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display3TV.setText(displayTime);
                        display3IV.setImageResource(R.mipmap.tab_arrow);
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate2() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                            display2TV.setText(display2Default);
                        }
                        date = "";
                        dateKind = "";

                        removeFilterListItem(display2Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display2Id);
                        bean.setFilterName(display2Default);
                        bean.setFilterType(display2Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        display2IV.setImageResource(R.mipmap.tab_arrow);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    removeFilterListItem(display2Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId("");

                    loading();
                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display2TV.setText(displayDate);
                        display2IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display2TV.setText(displayTime);
                        display2IV.setImageResource(R.mipmap.tab_arrow);
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);
    }

    private void showPopDate1() {
        if (datePopup == null) {
            datePopup = new DatePopWindow(getActivity());
            datePopup.setTimeListener(new DatePopWindow.TimeListener() {
                @Override
                public void setTime(String time, String typeDate) {
                    if ("".equals(time)) {
                        if ("dismiss".equals(typeDate)) {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                        } else {
                            display1IV.setImageResource(R.mipmap.tab_arrow);
                            display2IV.setImageResource(R.mipmap.tab_arrow);
                            display3IV.setImageResource(R.mipmap.tab_arrow);
                            display4IV.setImageResource(R.mipmap.tab_arrow);
                            display2TV.setText(display2Default);
                        }
                        date = "";
                        dateKind = "";

                        removeFilterListItem(display2Id);
                        FilterPatientBean bean = new FilterPatientBean();
                        bean.setDate("");
                        bean.setDateKind("");
                        bean.setFilterId(display2Id);
                        bean.setFilterName(display2Default);
                        bean.setFilterType(display2Type);
                        bean.setItemId("");

                        loading();
                        filterList.add(bean);
                        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
                        display2IV.setImageResource(R.mipmap.tab_arrow);
                        return;
                    }
                    dateKind = typeDate;

                    if ("0".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("1".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else if ("2".equals(typeDate)) {
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        try {
                            date = df.parse(time).getTime() + "";
                        } catch (ParseException e) {

                        }
                    } else {
                        date = "";
                    }

                    removeFilterListItem(display2Id);
                    FilterPatientBean bean = new FilterPatientBean();
                    bean.setDate(date);
                    bean.setDateKind(dateKind);
                    bean.setFilterId(display2Id);
                    bean.setFilterName(display2Default);
                    bean.setFilterType(display2Type);
                    bean.setItemId("");

                    loading();
                    filterList.add(bean);
                    YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

                    String displayTime = time.replaceAll("-", "/");
                    if (displayTime.length() > 7) {
                        String displayDate = displayTime.substring(2, displayTime.length());
                        display1TV.setText(displayDate);
                        display1IV.setImageResource(R.mipmap.tab_arrow);
                    } else {
                        display1TV.setText(displayTime);
                        display1IV.setImageResource(R.mipmap.tab_arrow);
                    }

                }
            });
        }
        datePopup.showAsDropDown(ivgLayout);

    }


    @Override
    public void onSelected(String type, UserManagerBean info) {
        if ("monitor".equals(type)) {
            Intent intent = new Intent(getActivity(), MonitorChart1Activity.class);
            intent.putExtra("patientId", info.getPatientId());
            intent.putExtra("isFromList", true);
            startActivity(intent);
        }
        if ("remind".equals(type)) {
//            Intent intent = new Intent(getActivity(), NoticeActivity.class);
//            intent.putExtra("patientId", info.getPatientId());
//            startActivity(intent);
            Intent intent = new Intent(getActivity(), PatientBetterPlanActivity.class);
            intent.putExtra("patientId", info.getPatientId());
            startActivity(intent);
        } else if ("chat".equals(type)) {
            Intent intent = new Intent(getActivity(), ChatFragmentActivity.class).putExtra(EaseConstant.EXTRA_USER_ID, "ejh" + info.getTel()).putExtra("name", info.getName());
            startActivity(intent);
        }
        if ("item".equals(type)) {
            Intent intent = new Intent(getActivity(), PatientInfoActivity.class);
            intent.putExtra("patientId", info.getPatientId());
            startActivity(intent);
        }
        YiJiaHuNetWorkUtils.userTalking(info.getPatientId(), handler);
    }

    @Override
    public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {
        isLoadMore = false;
        pageIndex = 1;
//        userManagerInfoList.clear();
        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);
    }

    @Override
    public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {

        if (userManagerInfoList.size() == totalCount) {
            isLoadMore = false;
            refreshLayout
                    .loadmoreFinish(PullToRefreshLayout.SUCCEED);
            return;
        }

        isLoadMore = true;
        pageIndex++;
        YiJiaHuNetWorkUtils.getPatientFilterResultList(filterList, "1", "", pageIndex, pageSize, handler);

    }
}
